import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:xinxuan/controllers/activity_controller/ActivityPageController.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:xinxuan/utils/activity_status_util.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:xinxuan/vo/activity_acquisitions_vo.dart';
import 'package:get/get.dart';

class ActivityNewUser extends StatelessWidget {

  final ActivityPageController controller;

  ActivityNewUser({
    required this.controller
  });

  @override
  Widget build(BuildContext context) {
    controller.stepIndex.value = 0;
    return Stack(
      children: [
        Positioned(
          top: 0,
          left: 0,
          child: Image.asset(
            'assets/images/image_activity_banner.png',
            height: 297.h,
            width: 375.w,
            fit: BoxFit.cover,
          )
        ),
        Column(
          children: [
            SizedBox(height: 241.h),
            Container(
              alignment: Alignment.center,
              padding: EdgeInsets.symmetric(horizontal: 12.w),
              child: Container(
                width: 351.w,
                padding: EdgeInsets.all(16.w),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(5.w),
                  color: bgWhiteColor
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      '${controller.activityAcquisitionsVo.value.data!.tips}',
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        color: textBlackColor,
                        fontSize: 14.sp
                      ),
                    ),
                    Container(
                      width: 253.w,
                      margin: EdgeInsets.only(top: 16.h),
                      child: _getBtn(),
                    )
                  ],
                ),
              ),
            ),
            _taskBar()
          ],
        ),
      ],
    );
  }

  Widget _taskBar() {
    return Container(
      margin: EdgeInsets.only(top: 12.h),
      padding: EdgeInsets.symmetric(horizontal: 12.w),
      child: Stack(
        children: [
          Container(
            width: 351.w,
            padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 16.h),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(5.w),
              color: bgWhiteColor
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '做任务领现金',
                  style: TextStyle(
                    color: textBlackColor,
                    fontSize: 14.sp,
                    fontWeight: FontWeight.bold
                  ),
                ),
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 8.w),
                  margin: EdgeInsets.only(top: 12.h),
                  child: controller.activityAcquisitionsVo.value.meta!.steps!.length > 0 ? Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: List.generate((controller.activityAcquisitionsVo.value.meta!.steps!.length * 2) - 1, (index) {
                      if (index != 0 && index.isEven) {
                        controller.stepIndex.value =  int.parse('${index ~/ 2}');
                      }
                      Steps item = controller.activityAcquisitionsVo.value.meta!.steps![ controller.stepIndex.value];
                      if ((index + 1) % 2 == 0) {
                        return Image.asset(
                          ActivityStatusUtil.getActivityStatusStepIcon(item.key!, controller.activityAcquisitionsVo.value.data!.status!),
                          width: 21.w,
                          height: 14.h,
                        );
                      } else {
                        return Container(
                          child: Column(
                            children: [
                              Image.asset(
                                ActivityStatusUtil.getActivityStatusIcon(item.key!, controller.activityAcquisitionsVo.value.data!.status!),
                                width: 36.w,
                                height: 36.w,
                              ),
                              SizedBox(height: 6.h),
                              Text(
                                '${item.val}',
                                style: TextStyle(
                                  color: textBlackColor,
                                  fontSize: 14.sp
                                ),
                              )
                            ],
                          ),
                        );
                      }
                    }),
                  ) : Container(),
                )
              ],
            ),
          ),
          Positioned(
            top: 0,
            right: 0,
            child: controller.activityAcquisitionsVo.value.data!.status! >= 4 ? Image.asset(
              'assets/icons/icon_activity_complete.png',
              width: 73.w,
              height: 73.w,
            ) : Container()
          )
        ],
      )
    );
  }

  Widget _getBtn() {
    Widget child = Container();
    switch (controller.activityAcquisitionsVo.value.data!.status!) {
      case 0:
        child = ButtonUtil(
          text: '立即参与活动', 
          fontSize: 14.sp, 
          borderRadius: 36.h, 
          height: 36.h, 
          onTop: () {
            controller.activityStep(1);
          }
        );
        break;
      case 1:
        child = ButtonUtil(
          text: '去完成认证', 
          fontSize: 14.sp, 
          borderRadius: 36.h, 
          height: 36.h, 
          onTop: () {
            controller.activityStep(2);
          }
        );
        break;
      case 2:
        child = ButtonUtil(
          text: '去完成抢购', 
          fontSize: 14.sp, 
          borderRadius: 36.h, 
          height: 36.h, 
          onTop: () {
            controller.activityStep(3);
          }
        );
        break;
      case 3:
        child = ButtonUtil(
          text: '立即领取', 
          fontSize: 14.sp, 
          borderRadius: 36.h, 
          height: 36.h, 
          onTop: () {
            controller.activityStep(4);
          }
        );
        break;
      default:  
        child = ButtonUtil(
          text: '邀请新用户', 
          fontSize: 14.sp, 
          borderRadius: 36.h, 
          height: 36.h, 
          onTop: () {
            Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.INVITATION_POSTER_PAGE}');
          }
        );
    }

    if (controller.activityAcquisitionsVo.value.data!.status! <= 1) {
      
    }
    return child;
  }
}